﻿using Service;
using System;

namespace Worker.Producer
{
    class Program
    {
        static void Main(string[] args)
        {
            var exchangeName = "TestExchange";
            var queueName = "TRabbitWokerMQ";
            var routingKey = "Woker";

            if (args.Length != 0)
            {

                MessageQueue mq = new MessageQueue("106.55.163.36", 5672, "admin", "qq1226550632");
                mq.CreateQueue(queueName);
                mq.BindQueue(queueName, exchangeName, routingKey);
                mq.SendMessage(routingKey, exchangeName, string.Join(" ", args), prop =>
                {
                    //消息持久化
                    prop.Persistent = true;
                    return prop;
                });
                mq.Execute(channel => 
                {
                    //消息调度控制
                    //prefetchSize 
                    //prefetchCount 一次不要给同一个worker提供多于一条的信息
                    channel.BasicQos(prefetchSize: 0, prefetchCount: 1, false);
                    return channel;
                });
                Console.WriteLine("Message Send.");
            }
        }
    }
}
